package com.yb.personelmanagement.service.init;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.yb.personelmanagement.domain.System.DataPermissionRepository;
import com.yb.personelmanagement.domain.System.DataRoleRepository;
import com.yb.personelmanagement.domain.System.PermissionRepository;
import com.yb.personelmanagement.domain.System.RoleRepository;
import com.yb.personelmanagement.domain.System.UserRepository;

/**
 * 
 * @author Shinelon
 *
 */
@Service
public class DatabaseLoader {
	
	@Autowired
	DataPermissionRepository  dataPermissionRepository;
	
	@Autowired
	DataRoleRepository dataRoleRepository;
	
	@Autowired
	PermissionRepository permissionRepository;
	
	@Autowired
	RoleRepository roleRepository;
	@Autowired
	UserRepository userRepository;
	
	@Value("${spring.jpa.hibernate.ddl-auto}")
	private String status;
	
	/**
	 * 
	 * @throws InterruptedException
	 */
	@PostConstruct
	private void initLoader() throws InterruptedException {
		if (status.equals("create") || status.equals("create-drop")) {

			dataPermissionRepository.saveAll(JurisdictionInit.dataPermissionListInit());
			dataRoleRepository.saveAll(JurisdictionInit.dataRoleListInit());
			permissionRepository.saveAll(JurisdictionInit.permissionListInit());
			roleRepository.saveAll(JurisdictionInit.roleListInit());
			userRepository.saveAll(JurisdictionInit.userListInit());
			
		
		}
	}

}
